import constants from './constants.js'

class Cache{
    setToken(token){
        if(token===undefined){
            return
        }
        window.localStorage.setItem(constants.tokenKey,JSON.stringify(token));
    }
    setUserName(username){
        if(username===undefined){
            return
        }
        window.localStorage.setItem(constants.usernameKey,JSON.stringify(username))
    }
    setUserId(userId){
        if(userId===undefined){
            return
        }
        window.localStorage.setItem(constants.userIdKey,JSON.stringify(userId))
    }

    getToken(){
        let result = window.localStorage.getItem(constants.tokenKey)
        return JSON.parse(result)
    }
    getUsername(){
        let result = window.localStorage.getItem(constants.usernameKey)
        return JSON.parse(result)
    }
    getUserId(){
        let result = window.localStorage.getItem(constants.userIdKey)
        return JSON.parse(result)
    }
}
export default new Cache()